<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Authentication Login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <!-- basic styles -->

    <link href="<?php echo TEMPLATE_SITE_PATH; ?>css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="<?php echo TEMPLATE_SITE_PATH; ?>css/font-awesome.min.css" />

    <!--[if IE 7]>
      <link rel="stylesheet" href="<?php echo TEMPLATE_SITE_PATH; ?>css/font-awesome-ie7.min.css" />
    <![endif]-->

    <!-- page specific plugin styles -->

    <!-- fonts -->

    <link rel="stylesheet" href="<?php echo TEMPLATE_SITE_PATH; ?>css/ace-fonts.css" />

    <!-- ace styles -->

    <link rel="stylesheet" href="<?php echo TEMPLATE_SITE_PATH; ?>css/ace.min.css" />
    <link rel="stylesheet" href="<?php echo TEMPLATE_SITE_PATH; ?>css/ace-rtl.min.css" />

    <!--[if lte IE 8]>
      <link rel="stylesheet" href="<?php echo TEMPLATE_SITE_PATH; ?>css/ace-ie.min.css" />
    <![endif]-->

    <!-- inline styles related to this page -->

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->

    <!--[if lt IE 9]>
    <script src="<?php echo TEMPLATE_SITE_PATH; ?>js/html5shiv.js"></script>
    <script src="<?php echo TEMPLATE_SITE_PATH; ?>js/respond.min.js"></script>
    <![endif]-->
        
    <style type="text/css">
      #page-loading {
        position: fixed;
        z-index: 9999;
        height: 100%;
        width: 100%;
        left: 0px;
        top: 0px;
      }
      
      #page-loading > img {
        z-index: inherit;
        position: inherit;
        width: 10%;
        left: 45%;
        top: 35%;
      }
    </style>
  </head>

  <body class="login-layout">
    <div class="main-container">
      <div class="main-content">
        <div class="row">
          <div class="col-sm-10 col-sm-offset-1">
            <div class="login-container">
              <div class="center">
                <h1>
                  <span class="white">Authentication</span>
                </h1>
              </div>

              <div class="space-6"></div>

              <div class="position-relative">
                            
              <?php if(isset($token) && !empty($token)) { ?>
                <div id="signup-box" class="signup-box widget-box no-border">
                  <div class="widget-body">
                    <div class="widget-main">
                      <h4 class="header green lighter bigger">
                        <i class="icon-group blue"></i>
                        Reset Password
                      </h4>

                      <div class="space-6"></div>
                      <p> Enter your new password: </p>

                      <?php echo form_open();?>
                        <fieldset>
                          <label class="block clearfix">
                            <span class="block input-icon input-icon-right">
                              <input type="password" class="form-control" id="rs-password" placeholder="Password" />
                              <i class="icon-lock"></i>
                            </span>
                          </label>

                          <label class="block clearfix">
                            <span class="block input-icon input-icon-right">
                              <input type="password" class="form-control" id="rs-repassword" placeholder="Repeat password" />
                              <i class="icon-retweet"></i>
                            </span>
                          </label>

                          <div class="space-6"></div>

                          <div class="clearfix">
                            <button type="button" id="btnChPassword" class="width-65 pull-right btn btn-sm btn-success">
                              Change Password
                            </button>
                          </div>
                        </fieldset>
                      </form>
                    </div>

                    <div class="toolbar center">
                      <a href="javascript: void(0);" onclick="show_box('login-box'); return false;" class="back-to-login-link">
                        Back to login
                        <i class="icon-arrow-right"></i>
                      </a>
                    </div>
                  </div><!-- /widget-body -->
                </div><!-- /signup-box -->
              <?php } // else { ?>
                <div id="login-box" class="login-box visible widget-box no-border">
                  <div class="widget-body">
                    <div class="widget-main">
                      <h4 class="header blue lighter bigger">
                        <i class="icon-bell-alt"></i>
                        Please Enter Your Information
                      </h4>
                                            
                      <?php echo ms_text(); ?>
                      <div class="space-6"></div>
                      <?php echo form_open();?>
                        <fieldset>
                          <label class="block clearfix">
                            <span class="block input-icon input-icon-right">
                              <?php echo form_input('username', set_value('username')?set_value('username'):$this->input->cookie('dn_u'),'class="form-control" placeholder="Username" autocomplete="off"');?>
                              <i class="icon-user"></i>
                            </span>
                          </label>

                          <label class="block clearfix">
                            <span class="block input-icon input-icon-right">
                              <?php echo form_password('password', set_value('password')?set_value('password'):$this->input->cookie('dn_p'),'class="form-control" placeholder="Password"');?>
                              <i class="icon-lock"></i>
                            </span>
                          </label>

                          <div class="space"></div>

                          <div class="clearfix">
                            <label class="inline">
                              <?php echo form_checkbox('remember','remember','','class="ace"'.($this->input->cookie('dn_u') ? ' checked' : ''));?>
                              <span class="lbl"> Remember Me</span>
                            </label>

                            <button type="submit" class="width-35 pull-right btn btn-sm btn-primary">
                              <i class="icon-key"></i>
                              Login
                            </button>
                          </div>

                          <div class="space-4"></div>
                        </fieldset>
                      <?php echo form_close();?>
                    </div><!-- /widget-main -->

                    <div class="toolbar clearfix">
                      <div>
                        <a href="javascript: void(0);" onclick="show_box('forgot-box'); return false;" class="forgot-password-link">
                          I forgot my password
                        </a>
                      </div>

                      <!--<div>
                        <a href="<?php //echo base_url(); ?>" class="user-signup-link">
                          Visite site
                          <i class="icon-arrow-right"></i>
                        </a>
                      </div>-->
                    </div>
                  </div><!-- /widget-body -->
                </div><!-- /login-box -->

                <div id="forgot-box" class="forgot-box widget-box no-border">
                  <div class="widget-body">
                    <div class="widget-main">
                      <h4 class="header red lighter bigger">
                        <i class="icon-key"></i>
                        Reset Password
                      </h4>

                      <div class="space-6"></div>
                      <p>
                        Enter your email and to receive instructions
                      </p>

                      <fieldset>
                        <label class="block clearfix">
                          <span class="block input-icon input-icon-right">
                            <input type="email" id="fg-email" class="form-control" placeholder="Email" />
                            <i class="icon-envelope"></i>
                          </span>
                        </label>

                        <div class="clearfix">
                          <button type="button" id="btnFgPwd" class="width-35 pull-right btn btn-sm btn-danger">
                            <i class="icon-lightbulb"></i>
                            Send Me!
                          </button>
                        </div>
                      </fieldset>
                    </div><!-- /widget-main -->

                    <div class="toolbar center">
                      <a href="javascript: void(0);" onclick="show_box('login-box'); return false;" class="back-to-login-link">
                        Back to login
                        <i class="icon-arrow-right"></i>
                      </a>
                    </div>
                  </div><!-- /widget-body -->
                </div><!-- /forgot-box -->
              <?php // } ?>   
              </div><!-- /position-relative -->
            </div>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div>
    </div><!-- /.main-container -->

    <!-- basic scripts -->

    <!--[if !IE]> -->

    <script type="text/javascript">
      window.jQuery || document.write('<script src="<?php echo TEMPLATE_SITE_PATH; ?>js/jquery-2.0.3.min.js">'+'<'+'/script>');
    </script>

    <!-- <![endif]-->

    <!--[if IE]>
        <script type="text/javascript">
         window.jQuery || document.write('<script src="<?php echo TEMPLATE_SITE_PATH; ?>js/jquery-1.10.2.min.js">'+'<'+'/script>');
        </script>
        <![endif]-->

    <script type="text/javascript">
      if("ontouchend" in document) document.write('<script src="<?php echo TEMPLATE_SITE_PATH; ?>js/jquery.mobile.custom.min.js">'+'<'+'/script>');
    </script>

    <script src="<?php echo TEMPLATE_SITE_PATH; ?>js/my.msg.js"></script>

    <!-- inline scripts related to this page -->
    <script type="text/javascript">
      <?php $csrf_token = config_item('csrf_token_name'); ?>
      <?php if(isset($token) && !empty($token)){ echo 'show_box("signup-box");'; } ?>
      
      function show_box(id) {
        jQuery('.widget-box.visible').removeClass('visible');
        jQuery('#'+id).addClass('visible');
      }

      $(document).ready(function(e) {
        $('#btnFgPwd').click(function(){
          loading.Show("<?php echo base_url('uploads'); ?>");
          jQuery.ajax({
            url : "<?php echo site_url('fgpwd'); ?>",
            type: "post",
            dataType: "json",
            data: {email: $('#fg-email').val(), <?php echo $csrf_token.': $(\'input[name="'.$csrf_token.'"]\').val()'; ?> },
            success:function(data){
              loading.Hide();
              alert(data.ms);
            },
            error:function(data){
              alert('Error: please try again later!');
            }
          });
        });
        
        $('#btnChPassword').click(function(){
          var pwd = $('#rs-password').val();
          var repwd = $('#rs-repassword').val();
          
          loading.Show("<?php echo base_url('uploads'); ?>");
          jQuery.ajax({
            url : "<?php echo site_url('chpwd/'.((isset($token) && !empty($token)) ? $token : '')); ?>",
            type: "post",
            dataType: "json",
            data: {password: pwd, repassword: repwd, <?php echo $csrf_token.': $(\'input[name="'.$csrf_token.'"]\').val()'; ?> },
            success:function(data){
              loading.Hide();
              alert(data.ms);
              if(data.type == 'success'){
                window.open('<?php echo site_url(); ?>');
                $('#rs-password, #rs-repassword').val('');
              }
            },
            error:function(data){
              alert('Error: please try again later!');
            }
          });
        });
      });
    </script>
  </body>
</html>
